package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.service.PrepaidCardService;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.CancelOrderBean;
import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.OrderGroupVo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.SellerCouponVo;
import com.ymatou.iapi.trading.operate.parameter.YmatouCouponVo;
import com.ymatou.iapi.trading.operate.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SellerCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.YmatouCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.CancelOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.model.YmtOrderInfo;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtOrderInfoWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;

/**
 * 取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CancelOrder {
	private static CancelOrderBean cancelorderbean;

	private static CancelOrderCall cancelordercall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订单");
	}

	@Before
	public void caseUp() {
		cancelorderbean = new CancelOrderBean();
		cancelordercall = new CancelOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelordercall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	// 创建2个买手多个订单，使用平台优惠券,商家券
	private Map placeOrder3() {

		Map map = new HashMap();

		try {

			PlaceOrderReq placeorderBean = PlaceOrderService
					.getDefaultOrderReq();

			int userId = placeorderBean.getUserId();

			OrderGroupVo orderGroupVo1 = placeorderBean.getOrderGroups().get(0);

			orderGroupVo1.getOrders().add(
					PlaceOrderService.getDefaultOrderVo(userId));

			int sellerId1 = orderGroupVo1.getSellerId();

			int sellerId2 = Integer.valueOf(EnvSetup.getData("SellerId"));

			OrderGroupVo orderGroupVo2 = PlaceOrderService
					.getDefaultOrderGroupVo(userId, sellerId2);

			placeorderBean.getOrderGroups().add(orderGroupVo2);

			YmatouCouponVo ymtCoupon = new YmatouCouponVo();

			// 平台优惠券
			BigDecimal couponValue = new BigDecimal(13);

			String couponCode = new OrderCallService().receivePlatformCoupon(
					userId, couponValue);

			ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);

			ymtCoupon.setCouponCode(couponCode);
			ymtCoupon.setCouponValue(couponValue);

			placeorderBean.setYmatouCoupon(ymtCoupon);

			// 商家优惠券
			BigDecimal sellerCouponValue = new BigDecimal(15);

			String sellerCouponCode = new CouponCallService()
					.receiveCouponInfo(sellerId1, userId, couponValue);

			SellerCouponVo sellerCoupon = new SellerCouponVo();

			sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon.setCouponCode(sellerCouponCode);
			sellerCoupon.setCouponValue(sellerCouponValue);

			orderGroupVo1.setSellerCoupon(sellerCoupon);

			// 商家优惠券
			BigDecimal sellerCouponValue2 = new BigDecimal(11);
			String sellerCouponCode2 = new CouponCallService()
					.receiveCouponInfo(sellerId2, userId, couponValue);

			SellerCouponVo sellerCoupon2 = new SellerCouponVo();

			sellerCoupon2.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon2.setCouponCode(sellerCouponCode2);
			sellerCoupon2.setCouponValue(sellerCouponValue2);

			orderGroupVo2.setSellerCoupon(sellerCoupon2);

			PlaceOrderResp placeOrderResp = PlaceOrderService
					.callPlaceOrderService(placeorderBean);

			map.put("userId", userId);
			map.put("orderId", placeOrderResp.getOrderList());
			map.put("tradingId", placeOrderResp.getTradingId());
			map.put("mainOrderId", placeOrderResp.getMainOrderId());

			map.put("ymtCouponCode", couponCode);
			map.put("sellerCouponCode1", sellerCouponCode);
			map.put("sellerCouponCode2", sellerCouponCode2);

		} catch (Exception e) {
			Logger.fail(e);
		}
		return map;
	}
	// 创建一个订单，使用平台公共有优惠券，商家私有优惠券
	private PlaceOrderResp placeOrder4() {

		PlaceOrderReq placeorderBean = PlaceOrderService.getDefaultOrderReq();

		YmatouCouponVo ymtCoupon = new YmatouCouponVo();
		// 平台优惠券
		BigDecimal couponValue = new BigDecimal(13);
		String couponCode = null;
		try {

			couponCode = new OrderCallService()
					.receivePlatformShortCodeCoupon(couponValue);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
		ymtCoupon.setCouponCode(couponCode);
		ymtCoupon.setCouponValue(couponValue);

		placeorderBean.setYmatouCoupon(ymtCoupon);

		return PlaceOrderService.callPlaceOrderService(placeorderBean);

	}

	private PlaceOrderResp createPreSaleOrder() {

		PlaceOrderReq placeorderBean = PlaceOrderService.getDefaultOrderReq();

		// 预售订单
		placeorderBean.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setPreSale(true);

		return PlaceOrderService.callPlaceOrderService(placeorderBean);
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_001() {
		Logger.start(true, "订单支付前,买家取消订单成功,订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_002() {
		Logger.start(true, "订单支付前,卖家取消订单成功,订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			// 卖家取消的时候，为卖家ID
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证 这里不new DefaultWapper会出现数据库close的情况，待确认原因
			Logger.verifyEquals(13,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			// Thread.sleep(30000);
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_003() {
		Logger.start(true, "订单支付前,超时未支付系统自动取消订单,订单状态为18 系统自动取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 修改订单自动取消时间为0
			new DefaultWapper().updateOrderAutoCancelOrderHoursByOrderId(0.00,
					orderId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_004() {
		Logger.start(true, "订单支付前,客服取消订单成功,订单状态为18 系统取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_005() {
		Logger.start(true, "订单卖家已接单,客服取消订单成功，订单状态为18 系统取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			/*
			 * // 商家发货 orderService.dispatched(orderId, sellerId); // 确认收货
			 * orderService.confirmReceive(userId, orderId);
			 */
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试客服取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_006() {
		Logger.start(true, "订单已支付商家未接单,风控取消订单成功，订单状态为18 系统自动取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试风控取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.RISKCONTROL_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId); // 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			/*
			 * YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
			 * "POST", "JSON"); String RiskControlNotifyString = "{OrderId:" +
			 * orderId + ",ParamExt:{\"Status\":\"Rejected\"}}";
			 * RiskControlNotifyCall.setUrl(
			 * "http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify"
			 * ); RiskControlNotifyCall.setData(RiskControlNotifyString);
			 * Logger.comment("风控检测"); RiskControlNotifyCall.callService();
			 */
			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_007() {
		Logger.start(true, "订单已支付商家未接单,买家取消订单成功，订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId,
					totalPrice.setScale(2), tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_008() {
		Logger.start(true, "订单已支付商家未接单,卖家取消订单成功，订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId,
					totalPrice.setScale(2), tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(13, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 13).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_009() {
		Logger.start(true, "订单已支付商家未接单,客服取消订单成功，订单状态为18 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId,
					totalPrice.setScale(2), tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(18, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 18).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_010() {
		Logger.start(true, "订单在退货退款中,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 退货退款同步
			orderService.applySalesRefundRequestInJava(orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals(String.format("哈尼，此单%s有退货/退款，请先去处理~", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_011() {
		Logger.start(false, "订单支付前,重复取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals(String.format("此订单%s已取消~", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_012() {
		Logger.start(false, "订单不存在");
		try {
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			int orderId = 11;
			cancelorderbean.setOrderId(orderId);
			int userId = 1113;
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains(ECode.FAILED201_MSG_11,
					cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_013() {
		Logger.start(true, "商家已接单,买家取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains("哈尼，你的订单" + orderId
					+ "，买手刚刚接单了，只能走退货退款流程了哦~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_014() {
		Logger.start(true, "订单已收货,,客服取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			// 商家发货
			orderService.dispatched(orderId, sellerId);
			// 确认收货
			orderService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("客服取消订单" + orderId + "状态不匹配",
					cancelordercall.getMsg(), "验证Msg");
			// 数据库验证
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_015() {
		Logger.start(false, "买家用户不是订单的所有者");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			String cancelReason = "自动化测试取消订单";
			Logger.comment("前置数据准备结束");
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId + 1);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("用户" + cancelorderbean.getUserId() + "不是订单"
					+ orderId + "的所有者", cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_016() {
		Logger.start(true, "订单已支付商家未接单,使用平台,商家优惠券风控取消订单成功,不退优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);

			Logger.comment("前置数据准备结束");
			/*
			 * YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
			 * "POST", "JSON"); String RiskControlNotifyString = "{OrderId:" +
			 * orderId + ",ParamExt:{\"Status\":\"Rejected\"}}";
			 * RiskControlNotifyCall.setUrl(
			 * "http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify"
			 * ); RiskControlNotifyCall.setData(RiskControlNotifyString);
			 * Logger.comment("风控检测"); RiskControlNotifyCall.callService();
			 */
			String cancelReason = "自动化测试风控取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.RISKCONTROL_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId); // 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);

			String ymtCouponCode = (String) ymtOrders.get(0).get(
					"sYmtCouponCode");

			String sellerCouponCode = (String) ymtOrders.get(0).get(
					"sSellerCouponCode");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			// 数据库验证

			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.verifyEquals(ymtCouponUsed, true, "验证ymt平台优惠券不退回");
			Logger.verifyEquals(sellerCouponCodeUsed, true, "验证商家优惠券不退回");

			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice.setScale(2), ymtActList.get(0)
					.getAmount(), "验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_017() {
		Logger.start(true, "接单前取消,退优惠券");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			// 数据库验证
			String ymtCouponCode = (String) ymtOrders.get(0).get(
					"sYmtCouponCode");

			String sellerCouponCode = (String) ymtOrders.get(0).get(
					"sSellerCouponCode");

			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtCouponUsed, false, "验证ymt平台优惠券退回");
			Logger.verifyEquals(sellerCouponCodeUsed, false, "验证商家优惠券退回");

			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice.setScale(2), ymtActList.get(0)
					.getAmount(), "验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_018() {
		Logger.start(true, "使用平台,商家优惠券.接单后客服取消订单,不退优惠券");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);

			String ymtCouponCode = (String) ymtOrders.get(0).get(
					"sYmtCouponCode");

			String sellerCouponCode = (String) ymtOrders.get(0).get(
					"sSellerCouponCode");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证
			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtCouponUsed, true, "验证ymt平台优惠券不退回");
			Logger.verifyEquals(sellerCouponCodeUsed, true, "验证商家优惠券不退回");

			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice.setScale(2), ymtActList.get(0)
					.getAmount(), "验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_019() {
		Logger.start(true, "未付款状态,同一主单号下面订单全部取消,平台优惠券退回");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orderIds = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId1 = orderIds.get(0).getOrderId();
			int orderId2 = orderIds.get(1).getOrderId();

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";

			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId1);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId1);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId1);

			String ymtCouponCode = (String) ymtOrders.get(0).get(
					"sYmtCouponCode");

			String sellerCouponCode = (String) ymtOrders.get(0).get(
					"sSellerCouponCode");

			// 数据库验证
			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtCouponUsed, true,
					"验证同一主单下,订单没有全部取消,ymt平台优惠券不退回");
			Logger.verifyEquals(sellerCouponCodeUsed, true,
					"验证同一主单下,订单没有全部取消,商家优惠券不退回");

			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			Logger.comment("退第2个订单:" + orderId2);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtCouponUsed, false,
					"验证同一主单下,订单全部取消。ymt平台优惠券退回");
			Logger.verifyEquals(sellerCouponCodeUsed, false,
					"验证同一主单下,订单全部取消,商家优惠券退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_020() {
		Logger.start(true, "已付款状态:同一主单号下面只有1个商家的订单,订单全部取消才退回平台优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orderIds = placeOrderResp.getOrderList();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId1 = orderIds.get(0).getOrderId();
			int orderId2 = orderIds.get(1).getOrderId();

			BigDecimal totalPrice1 = orderService
					.getNeedPrePayAmountOfCash(orderId1);
			BigDecimal totalPrice2 = orderService
					.getNeedPrePayAmountOfCash(orderId2);

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice1.add(totalPrice2),
					tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId1);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(5000);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId1);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") != 14)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId1);

			String ymtCouponCode = (String) ymtOrders.get(0).get(
					"sYmtCouponCode");

			String sellerCouponCode = (String) ymtOrders.get(0).get(
					"sSellerCouponCode");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId1));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			// 数据库验证

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			Logger.comment("退第2个订单:" + orderId2);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(3000);

			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId2);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode);

			Logger.verifyEquals(ymtCouponUsed, false,
					"验证同一主单下,订单没有全部取消,ymt平台优惠券退回");
			Logger.verifyEquals(sellerCouponCodeUsed, false,
					"验证同一主单下,订单没有全部取消,商家优惠券退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_021() {
		Logger.start(true, "已付款状态:同一主单号下面有多个商家的订单,即使订单全部取消,退回商家券,不退回平台优惠券");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			Map map = placeOrder3();

			List<Order> orderIds = (List<Order>) map.get("orderId");

			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");

			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode1 = (String) map.get("sellerCouponCode1");
			String sellerCouponCode2 = (String) map.get("sellerCouponCode2");

			int orderId1 = orderIds.get(0).getOrderId();
			int orderId2 = orderIds.get(1).getOrderId();
			int orderId3 = orderIds.get(2).getOrderId();

			BigDecimal totalPrice1 = orderService
					.getNeedPrePayAmountOfCash(orderId1);
			BigDecimal totalPrice2 = orderService
					.getNeedPrePayAmountOfCash(orderId2);
			BigDecimal totalPrice3 = orderService
					.getNeedPrePayAmountOfCash(orderId3);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice1.add(totalPrice2)
					.add(totalPrice3), tradingId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId1);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(5000);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 订单主表
			List<Map> ymtOrders = new ArrayList<Map>();

			ymtOrders = database.selectOrderByOderId(orderId1);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.comment("退第2个订单:" + orderId2);

			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(5000);

			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId2);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.comment("退第3个订单:" + orderId3);
			cancelorderbean.setOrderId(orderId3);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(5000);

			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId3);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId3), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId3, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId3, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			// 数据库验证
			boolean ymtCouponUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(ymtCouponCode);

			boolean sellerCouponCodeUsed = com.ymatou.iapi.optrade.testcase.Ts_CancelOrder
					.isCouponCodeUsed(sellerCouponCode1);

			Logger.verifyEquals(ymtCouponUsed, true,
					"验证同一主单下,订单没有全部取消,ymt平台优惠券不退回");
			Logger.verifyEquals(sellerCouponCodeUsed, false,
					"验证同一主单下,订单没有全部取消,商家优惠券不退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_023() {
		Logger.start(true, "订单用余额全款付款后,卖家接单前取消订单,校验资金退账户余额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					totalPrice.setScale(2), tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice.setScale(2), ymtActList.get(0)
					.getAmount(), "验证用户账户流水表取消订单退回用户支付的余额");
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					BigDecimal.ZERO.setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_024() {
		Logger.start(true,
				"订单用余额+支付宝组合支付,卖家接单前取消订单,校验使用余额支付退余额,使用第三方支付宝,原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(5);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payTpye = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payTpye);
			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall(payTpye,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall(payTpye,
					String.valueOf(thirdTradingId), userId);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理
			Thread.sleep(10000);
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementList
							.get(0).get("BusinessNo"));
			if (ymtActList.size() > 0) {
				BigDecimal refundAmout = ymtActList.stream()
						.filter(act -> act.getMemo().equals("取消订单"))
						.map(act -> act.getAmount()).reduce(BigDecimal::add)
						.get();
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals(
						(BigDecimal) settlementList.get(0)
								.get("fAccountAmount"), refundAmout,
						"验证用户账户流水表Amount");
			}
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					blanceAmout.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals("REFUND_SUCCESS",
					accountRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals((totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_025() {
		Logger.start(true, "订单用余额+微信组合支付,卖家接单前取消订单,校验使用第三方微信，原路退回微信");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(5);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payTpye = "15";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payTpye);
			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall(payTpye,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall(payTpye,
					String.valueOf(thirdTradingId), userId);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理
			// Thread.sleep(10000);
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementList
							.get(0).get("BusinessNo"));
			if (ymtActList.size() > 0) {
				BigDecimal refundAmout = ymtActList.stream()
						.filter(act -> act.getMemo().equals("取消订单"))
						.map(act -> act.getAmount())
						.reduce(BigDecimal.ZERO, BigDecimal::add);
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals(
						(BigDecimal) settlementList.get(0)
								.get("fAccountAmount"), refundAmout,
						"验证用户账户流水表Amount");
			}
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					blanceAmout.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals("REFUND_SUCCESS",
					accountRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals((totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_026() {
		Logger.start(true, "订单用支付宝全款支付,卖家接单前取消订单,校验原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(0);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payTpye = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payTpye);
			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall(payTpye,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall(payTpye,
					String.valueOf(thirdTradingId), userId);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理
			// Thread.sleep(10000);
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null,
					ymtOrderState.get(0).get("fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals((totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_027() {
		Logger.start(true, "订单用微信全款支付,卖家接单前取消订单,校验原路退回微信");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(0);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "15";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId), userId);
			// Thread.sleep(10000);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null,
					ymtOrderState.get(0).get("fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals((totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_028() {
		Logger.start(true, "订单用余额+第三方组合支付定金和尾款,卖家发货前取消订单,校验退款余额和第三方支付的原路返回。");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService oderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 付定金需要的全款金额
			BigDecimal earnestTotalAmout = totalPrice;

			// 支付定金用的账户余额
			BigDecimal earnestBlanceAmout = new BigDecimal(5);
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					earnestBlanceAmout, tradingId, payType);
			// 支付通知回调
			PayGateWayCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					earnestTotalAmout.subtract(earnestBlanceAmout).toString(),
					userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			// 接单
			oderService.acceptOrder(orderId, sellerId);
			// 总需要支付的尾款金额
			BigDecimal postPayTotalAmout = oderService
					.getPayableAmount(orderId).subtract(earnestTotalAmout);
			// 申请补款
			oderService.applyForPostPay(orderId, sellerId, postPayTotalAmout);
			// 补款
			// 账户余额支付的尾款金额
			BigDecimal postPayBlanceAmout = new BigDecimal(17);
			oderService.orderPostPayRequest(userId, postPayBlanceAmout,
					orderId, payType);
			// 查询补款生成的第三方交易号
			String thirdPostPayTradingId = (String) new DefaultWapper()
					.selectPostPayTradingInfo(orderId).get(0)
					.get("PostPayTradingId");
			// 支付通知回调
			PayGateWayCallService.notifyCall(payType, thirdPostPayTradingId,
					postPayTotalAmout.subtract(postPayBlanceAmout).toString(),
					userId);
			// 等待支付网关异步处理
			// Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退定金 的通知回调
			PayGateWayCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),

					userId);
			// 支付网关退补款 的通知回调
			PayGateWayCallService.refundNotifyCall(payType,
					thirdPostPayTradingId,

					userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(18, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(earnestTotalAmout.add(postPayTotalAmout),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementList
							.get(0).get("BusinessNo"));
			if (ymtActList.size() > 0) {
				BigDecimal refundAmout = ymtActList.stream()
						.filter(act -> act.getMemo().equals("取消订单"))
						.map(act -> act.getAmount()).reduce(BigDecimal::add)
						.get();
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals(
						(BigDecimal) settlementList.get(0)
								.get("fAccountAmount"), refundAmout,
						"验证用户账户流水表Amount");
			}

			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(earnestBlanceAmout.add(postPayBlanceAmout)
					.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					earnestTotalAmout
							.subtract(earnestBlanceAmout)
							.add(postPayTotalAmout.subtract(postPayBlanceAmout))
							.setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");

			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					earnestTotalAmout.add(postPayTotalAmout),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					earnestBlanceAmout.add(postPayBlanceAmout).setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.verifyEquals(
					earnestTotalAmout.subtract(earnestBlanceAmout).setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");

			Logger.verifyEquals(
					postPayTotalAmout.subtract(postPayBlanceAmout).setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPostPaidAmountToThirdParty"),
					"验证fRefundedPostPaidAmountToThirdParty");

			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals("REFUND_SUCCESS",
					accountRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			Logger.verifyEquals(earnestBlanceAmout.add(postPayBlanceAmout)
					.setScale(2),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals(
					(earnestTotalAmout.subtract(earnestBlanceAmout))
							.setScale(2), (BigDecimal) thirdPartyRefund.get(0)
							.get("RefundAmount"), "验证RefundAmount");
			Logger.verifyEquals("REST",
					thirdPartyRefund.get(1).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(1).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals(
					(postPayTotalAmout.subtract(postPayBlanceAmout))
							.setScale(2), (BigDecimal) thirdPartyRefund.get(1)
							.get("RefundAmount"), "验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_029() {
		Logger.start(true, "一笔交易生成多个订单,(用户余额+第三方组合支付),取消其中一单。校验退款余额和第三方支付的原路返回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService oderService = new OrderCallService();

			Map map = placeOrder3();

			List<Order> orderIds = (List<Order>) map.get("orderId");
			int mainOrderId = (Integer) map.get("mainOrderId");
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int tradingId = (Integer) map.get("tradingId");
			int orderId1 = orderIds.get(0).getOrderId();
			// 付定金需要的全款金额
			BigDecimal earnestTotalAmout = oderService
					.getNeedPrePayAmountOfCashBymainOrderId(mainOrderId);
			// 支付定金用的账户余额
			BigDecimal earnestBlanceAmout = new BigDecimal(36);
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					earnestBlanceAmout, tradingId, payType);
			// 支付通知回调
			PayGateWayCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					earnestTotalAmout.subtract(earnestBlanceAmout).toString(),
					userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退定金 的通知回调
			PayGateWayCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),

					userId);
			// Thread.sleep(10000);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId1);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId1);
			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId1);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId1);
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.comment("验证Ymt_SettlementInvoice表");

			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementList
							.get(0).get("BusinessNo"));
			if (ymtActList.size() > 0) {
				BigDecimal refundAmout = ymtActList.stream()
						.filter(act -> act.getMemo().equals("取消订单"))
						.map(act -> act.getAmount()).reduce(BigDecimal::add)
						.get();
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals(
						(BigDecimal) settlementList.get(0)
								.get("fAccountAmount"), refundAmout,
						"验证用户账户流水表Amount");
			}
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfThirdParty"),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");

			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfThirdParty"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");
			Logger.verifyEquals(
					null,
					ymtOrderState.get(0).get(
							"fRefundedPostPaidAmountToThirdParty"),
					"验证fRefundedPostPaidAmountToThirdParty");

			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals("REFUND_SUCCESS",
					accountRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfThirdParty"),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_030() {
		Logger.start(true, "订单用招行全款支付,卖家接单前取消订单,校验原路退回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = new BigDecimal(new Random().nextInt(10))
					.toString();

			PayGateWayCallService.cmbNotifyCall(String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId,
					cmbDiscountAmount);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId), userId);
			Thread.sleep(5000);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理

			// 取消订单，使用招行支付，退款金额减掉招行补贴金额
			BigDecimal refundAmout = totalPrice.subtract(blanceAmout).subtract(
					new BigDecimal(cmbDiscountAmount));

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(refundAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					refundAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.verifyEquals(
					new BigDecimal(cmbDiscountAmount).setScale(2),
					(BigDecimal) settlementList.get(0).get(
							"ThirdPartyDiscountAmount"),
					"验证退款结算单ThirdPartyDiscountAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					refundAmout.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null,
					ymtOrderState.get(0).get("fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.verifyEquals(
					refundAmout.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");

			Logger.verifyEquals(
					new BigDecimal(cmbDiscountAmount).setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedDiscountOfThirdParty"),
					"验证fRefundedDiscountOfThirdParty");

			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			/*
			 * Logger.verifyEquals("REFUND_SUCCESS",
			 * thirdPartyRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			 */
			Logger.verifyEquals(refundAmout.setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_031() {
		Logger.start(true, "一笔交易生成多个订单,(用户余额+招行支付),取消其中一单。校验退款余额和第三方支付的原路返回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService oderService = new OrderCallService();

			Map map = placeOrder3();

			List<Order> orderIds = (List<Order>) map.get("orderId");
			int mainOrderId = (Integer) map.get("mainOrderId");
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int tradingId = (Integer) map.get("tradingId");
			int orderId1 = orderIds.get(0).getOrderId();
			// 付定金需要的全款金额
			BigDecimal earnestTotalAmout = oderService
					.getNeedPrePayAmountOfCashBymainOrderId(mainOrderId);
			// 支付定金用的账户余额
			BigDecimal earnestBlanceAmout = new BigDecimal(36);
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					earnestBlanceAmout, tradingId, payType);

			// 支付网关支付回调交易
			String cmbDiscountAmount = new BigDecimal(new Random().nextInt(10))
					.toString();

			PayGateWayCallService.cmbNotifyCall(String.valueOf(thirdTradingId),
					earnestTotalAmout.subtract(earnestBlanceAmout).toString(),
					userId, cmbDiscountAmount);
			// 等待支付网关异步处理
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退定金 的通知回调
			PayGateWayCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),

					userId);
			// Thread.sleep(10000);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 订单商品明细
			List<YmtOrderInfo> ymtOrdersInfoList = new YmtOrderInfoWapper()
					.selectByOrderId(orderId1);
			// 计算该订单下使用的招行平台优惠金额
			Logger.comment("校验订单号:" + orderId1);
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId1);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId1);
			// 招行平台补贴金额
			BigDecimal orderRefundDiscountAmount = (BigDecimal) ymtOrderState
					.get(0).get("fDiscountOfThirdParty");

			// 订单余额退款表
			List<Map> accountRefund = database
					.selectAccountRefundInstruction(orderId1);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId1);
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			Logger.comment("验证Ymt_SettlementInvoice表");

			Logger.verifyEquals(
					((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash")),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementList
							.get(0).get("BusinessNo"));
			if (ymtActList.size() > 0) {
				BigDecimal refundAmout = ymtActList.stream()
						.filter(act -> act.getMemo().equals("取消订单"))
						.map(act -> act.getAmount()).reduce(BigDecimal::add)
						.get();
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals(
						(BigDecimal) settlementList.get(0)
								.get("fAccountAmount"), refundAmout,
						"验证用户账户流水表Amount");
			}
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					((BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfThirdParty")),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");

			Logger.verifyEquals(
					((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash")),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.verifyEquals(
					((BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfThirdParty")),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");
			Logger.verifyEquals(
					null,
					ymtOrderState.get(0).get(
							"fRefundedPostPaidAmountToThirdParty"),
					"验证fRefundedPostPaidAmountToThirdParty");
			Logger.verifyEquals(orderRefundDiscountAmount, ymtOrderState.get(0)
					.get("fRefundedDiscountOfThirdParty"),
					"验证fRefundedDiscountOfThirdParty");
			Logger.comment("验证Ymt_AccountRefundInstruction表");
			Logger.verifyEquals("CANCEL_ORDER",
					accountRefund.get(0).get("RefundSourceType"),
					"验证RefundSourceType");
			Logger.verifyEquals("REFUND_SUCCESS",
					accountRefund.get(0).get("RefundStatus"), "验证RefundStatus");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					(BigDecimal) accountRefund.get(0).get("BuyerFundInAmount"),
					"验证BuyerFundInAmount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals(
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_032() {
		Logger.start(true, "预售商品订单，买手接单后,买手取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = createPreSaleOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(13, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 13).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			Logger.verifyEquals(false,
					(Boolean) ymtOrders.get(0).get("bCanEvaluate"),
					"验证订单确认收货后可以评价");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_033() {
		Logger.start(true, "预售商品订单，买手接单后,买家取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = createPreSaleOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains("哈尼，你的订单" + orderId
					+ "，买手刚刚接单了，只能走退货退款流程了哦~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_034() {
		Logger.start(true, "预售商品订单，买手接单后,客服取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = createPreSaleOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(18, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 18).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_035() {
		Logger.start(true, "预售商品订单,付款后，超过120小时未接单，用户取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			DefaultWapper database = new DefaultWapper();

			OrderCallService orderService = new OrderCallService();

			PlaceOrderResp placeOrderResp = createPreSaleOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);

			database.updateOrderPaidTimeByOrderId(orderId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			Logger.verifyEquals(false,
					(Boolean) ymtOrders.get(0).get("bCanEvaluate"),
					"验证订单确认收货后可以评价");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	// 手工校验发送返库存消息 send trading_addproductstock message
	public void Tc_CancelOrder_036() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易组团成功后,取消订单成功.交易发送返库存消息");
		try {
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);

			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 3);

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId1),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_037() {
		Logger.start(true, "砍价团订单下单成功后,不允许手工取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder1(null);

			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_038() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易消息之前,不允许取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_039() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易开团成功,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 1);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_040() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易参团成功,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);

			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId2, 2, 2);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_041() {
		Logger.start(true, "库存为交易这边扣，取消订单，交易发送返回库存消息");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder9();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_042() {
		Logger.start(true, "订单用宝付全款支付,卖家接单前取消订单,校验原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payTpye = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payTpye);
			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("70",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(10000);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 支付网关退款回调交易
			PayGateWayCallService.refundNotifyCall("70",
					String.valueOf(thirdTradingId), userId);
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 等待支付网关异步处理
			// Thread.sleep(10000);
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);

			settlementList = settlementList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 3)
					.collect(Collectors.toList());

			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// 订单第三方退款表
			List<Map> thirdPartyRefund = database
					.selectThirdPartyRefundInstruction(orderId);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.comment("验证Ymt_SettlementInvoice表");
			Logger.verifyEquals(totalPrice.setScale(2),
					(BigDecimal) settlementList.get(0).get("CashAmount"),
					"验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals("取消订单退款结算",
					(String) settlementList.get(0).get("ProcessResult"),
					"验证退款结算单ProcessResult");
			Logger.verifyEquals(blanceAmout.setScale(2),
					(BigDecimal) settlementList.get(0).get("fAccountAmount"),
					"验证退款结算单fAccountAmount");
			Logger.verifyEquals(
					(totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) settlementList.get(0).get("fThirdPartyAmount"),
					"验证退款结算单fThirdPartyAmount");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					totalPrice.setScale(2),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null,
					ymtOrderState.get(0).get("fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.comment("验证Ymt_ThirdPartyRefundInstruction表");
			Logger.verifyEquals("EARNEST",
					thirdPartyRefund.get(0).get("TradingType"), "验证TradingType");
			Logger.verifyEquals("REFUND_SUCCESS",
					thirdPartyRefund.get(0).get("RefundStatus"),
					"验证RefundStatus");
			Logger.verifyEquals((totalPrice.subtract(blanceAmout)).setScale(2),
					(BigDecimal) thirdPartyRefund.get(0).get("RefundAmount"),
					"验证RefundAmount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_043() {
		Logger.start(true, "订单一个商品,退款拒绝后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder5();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			//拒绝退款
			orderService.salesrefundfailRequestAllProducts(orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_044() {
		Logger.start(true, "多商品订单,退款拒绝后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			//拒绝退款
			orderService.salesrefundfailRequestAllProducts(orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_045() {
		Logger.start(true, "多商品订单,其中一个商品全部退货退款成功后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			//退款
			orderService.salesRefundSuccessRequestInJava(orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_046() {
		Logger.start(true, "多商品订单,其中一个商品部分退货成功后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			//退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderService
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().remove(0);
			applysalesrefundrequestBean.getSalesRefundInfoList().remove(0);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundProductNum(1);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(BigDecimal.TEN);

			orderService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			orderService.salesrefundsuccessrequest(applysalesrefundrequestBean);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_047() {
		Logger.start(true, "多商品订单,部分商品退货的数量大于实际购买数量,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice.setScale(2),
					tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			//退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderService
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().remove(0);
			applysalesrefundrequestBean.getSalesRefundInfoList().remove(0);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundProductNum(10);

			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(BigDecimal.TEN);

			orderService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			orderService.salesrefundsuccessrequest(applysalesrefundrequestBean);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();

			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(orderId));
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			// 数据库验证

			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_048() {
		Logger.start(true, "微店订单接单后,商家取消订单成功");
		try {
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeLiveWechar(LogisticsTypeEnum.PackageDelivery);

			int userId = placeOrderResp.getUserId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			// 买家付款
			new OrderCallService().orderPayRequest(userId,
					placeOrderResp.getPayAmount(),
					placeOrderResp.getTradingId());

			Thread.sleep(2000);

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(13, database.getTradingStatus(orderId1),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_049() {
		Logger.start(true, "使用了预付卡订单,付款前取消订单");
		try {
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = PrepaidCardService
					.placeOrder(false);

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId1 = orders.get(0).getOrderId();

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证

			Thread.sleep(2000);

			DefaultWapper database = new DefaultWapper();

			List<Map> orderList = database.selectOrderByOderId(orderId1);

			Logger.verifyEquals(13, orderList.get(0).get("iTradingStatus"),
					"验证订单交易状态");

			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId1, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			DataUtil.verifyDateEquals(
					(BigDecimal) orderList.get(0).get("fPrepaidAmount"),
					PrepaidCardService.getCardEntry(userId,
							String.valueOf(orderId1)), "校验取消订单退回的预付卡金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_050() {
		Logger.start(true, "使用了预付卡订单,余额+第三方支付后，取消订单");
		try {
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = PrepaidCardService
					.placeOrder(false);

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			int orderId1 = orders.get(0).getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();

			// 用余额支付
			BigDecimal blanceAmout = new BigDecimal(0);

			// 买家付款
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId);

			new OrderCallService().orderPayCallBack(String
					.valueOf(thirdTradingId));

			Thread.sleep(3000);

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER
							.getCode());
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Thread.sleep(2000);

			DefaultWapper database = new DefaultWapper();

			List<Map> orderList = database.selectOrderByOderId(orderId1);

			Logger.verifyEquals(13, orderList.get(0).get("iTradingStatus"),
					"验证订单交易状态");

			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId1, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");

			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");

			DataUtil.verifyDecimalEquals(
					(BigDecimal) orderList.get(0).get("fPrepaidAmount"),
					PrepaidCardService.getCardEntry(userId,
							String.valueOf(orderId1)), "校验取消订单退回的预付卡金额");

			DataUtil.verifyDecimalEquals(
					(BigDecimal) orderList.get(0).get("fPayableAmount"),
					RefundService.getAccountEntry(userId, null,
							String.valueOf(orderId1)).getAmount(),
					"校验取消订单退回的资金账户金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
